/**
 * Copyright (c) 2017-present, Liu Jinyong
 * All rights reserved.
 *
 * https://github.com/huanxsd/MeiTuan  
 * @flow
 */


import React, { PureComponent } from 'react'
import { View, Text, TextInput, StyleSheet, ScrollView,TouchableOpacity, ListView, Image, InteractionManager } from 'react-native'
import RefreshListView, { RefreshState } from 'react-native-refresh-list-view'
import Amazeuivercode from '../../../common/Amazeuivercode'
import { color, NavigationItem, Button, Separator, SpacingView } from '../../../widget'
import { screen, system } from '../../../common'
import * as api from '../../../api'
type Props = {
    navigation: any,
}

type State = {
    name: string,
    phonenumber: number,
    piccode: string,
    vercode:string,
    referphone:number,
    storeName:string,
    tagline:string
}


class ApplyForDzScene extends PureComponent<Props, State> {

    static navigationOptions = ({ navigation }: any) => ({
        headerTitle: '申请成为店主',
        // headerStyle: {backgroundColor: 'white',fontSize:'4'},

    })

    constructor(props: Props) {
        super(props)
        this.state={
            name: '',
            phonenumber:'',
            piccode: '',
            vercode:'',
            referphone:'',
            storeName:'',
            tagline:''

        }
    
    }
 
    submitApply =  ()=> {
       
            let opendata=new Object();
            opendata.id=this.props.navigation.state.params.id,
            opendata.openId=this.props.navigation.state.params.id,
            opendata.name=this.state.name;
            opendata.storeName=this.state.storeName;
            opendata.tagline=this.state.tagline;
            opendata.phone=this.state.phonenumber;
            opendata.newRefer=this.state.referphone;
            opendata.status=4;
           let data=JSON.stringify(opendata);
           console.log(data+"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
            // try {
            //     let json = await api.doPost("/user/openStore", {data})
            //     if(json.msg=='checkfalse'){
            //         alert('成功');
            //     }
            //     else{
            //         alert(json.msg);
            //     }
            // } catch (error) {
            //     alert('请求失败，请重试' + error)
            // }
            this.props.navigation.navigate('ApplyForDzIng');
    }
    render() {

        return (
            <View >

                {/*输入姓名*/}
                <View style={styles.textcontainer}>
                    <View style={styles.textview}>
                        <Text style={styles.textfont}>姓名：</Text>
                    </View>
                    <View style={styles.TextInputview}>
                        <TextInput style={styles.textfont} requer="" textAlign="right" underlineColorAndroid='transparent'
                            onChangeText={(name) => this.setState({ name:name })} placeholder="请输入姓名">
                        </TextInput>
                    </View>
                </View>

                {/*输入手机号*/}
                <View style={styles.textcontainer}>
                    <View style={styles.textview}>
                        <Text style={styles.textfont}>手机号：</Text>
                    </View>
                    <View style={styles.TextInputview}>
                        <TextInput style={styles.textfont} textAlign="right" underlineColorAndroid='transparent'
                            onChangeText={(phonenumber) => this.setState({ phonenumber:phonenumber })}
                            maxLength={11}
                            keyboardType='numeric'
                            placeholder="请输入手机号">
                        </TextInput>
                    </View>
                </View>

                {/*输入图形验证码*/}
                <View style={styles.textcontainer}>
                    <View style={styles.textview}>
                        <Text style={styles.textfont}>图形验证码：</Text>
                    </View>
                    <View style={styles.TextInputview}>
                        <Amazeuivercode size={4}  captchaType="Normal" >
                        </Amazeuivercode>
                    </View>
                </View>

                {/*输入验证码*/}
                <View style={styles.textcontainer}>
                    <View style={styles.textview}>
                        <Text style={styles.textfont}>验证码：</Text>
                    </View>
                    <View style={styles.TextInputview}>
                        <TextInput style={styles.textfont} textAlign="right" underlineColorAndroid='transparent'
                            onChangeText={(vercode) => this.setState({ vercode:vercode })}
                            placeholder="请输入验证码">
                        </TextInput>
                    </View>
                </View>

                {/*输入推荐人手机号*/}
                <View style={styles.textcontainer}>
                    <View style={styles.textview}>
                        <Text style={styles.textfont}>推荐人手机号：</Text>
                    </View>
                    <View style={styles.TextInputview}>
                        <TextInput style={styles.textfont} textAlign="right" underlineColorAndroid='transparent'
                            onChangeText={(referphone) => this.setState({ referphone:referphone })}
                            maxLength={11}
                            keyboardType='numeric'
                            placeholder="请输入推荐人手机号">
                        </TextInput>
                    </View>
                </View>

                {/*输入店铺名称*/}
                <View style={styles.textcontainer}>
                    <View style={styles.textview}>
                        <Text style={styles.textfont}>店铺名称：</Text>
                    </View>
                    <View style={styles.TextInputview}>
                        <TextInput style={styles.textfont} textAlign="right" underlineColorAndroid='transparent'
                            onChangeText={(storeName) => this.setState({ storeName:storeName })}
                            maxLength={11}
                            keyboardType='numeric'
                            placeholder="请输入店铺昵称">
                        </TextInput>
                    </View>
                </View>
                <SpacingView />
                <SpacingView />
                <SpacingView />
                <View style={{ alignItems: 'center' }}>
                    <Button
                        title='提交申请'
                        titleStyle={{color: 'white', fontSize: 14}}
                        style={styles.ApplyButton}
                        onPress={()=>this.submitApply()}
                    />
                </View>
               
            </View>
        )
    }

}


const styles = StyleSheet.create({
    
    ApplyButton: {
        backgroundColor: '#fc9e28',
        width: screen.width * 2 / 3,
        height: 30,
        borderRadius: 7,
        alignItems: 'center',
    },
   
    textcontainer: {
        flexDirection: 'row',
        backgroundColor: 'white',
        height: 38,
        borderBottomWidth: screen.onePixel,
        borderColor: color.border,
        alignItems: 'center'
    },
    textview: {
        paddingLeft: screen.width / 17,
        //width: screen.width / 5,
        justifyContent: 'center',
        alignItems: 'center',

    },
    TextInputview: {
        flex: 1,
        justifyContent: 'center',
        paddingRight: screen.width / 20,
    },
    textfont: {
        fontSize: 12,
    }
})


export default ApplyForDzScene
